package com.kehao.leetcode.jzoffer;


import org.junit.Test;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author  Kehao.Chen
 * @date  2022/6/29 15:50
 * @version 1.0
 */
public class JZSolution042 {

    private static class RecentCounter {

        Queue<Integer> queue = new LinkedList<>();

        public RecentCounter() {
            queue.clear();
        }

        public int ping(int t) {
            queue.add(t);
            while (!queue.isEmpty()&&t-queue.peek()>3000){
                queue.poll();
            }
            return queue.size();
        }
    }

    @Test
    public void test(){
        RecentCounter recentCounter = new RecentCounter();
        System.out.println(recentCounter.ping(1));
        System.out.println(recentCounter.ping(100));
        System.out.println(recentCounter.ping(3001));
        System.out.println(recentCounter.ping(3002));
    }
}
